/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gob.pnp.servlets;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import pe.gob.pnp.actions.Usuario;

/**
 *
 * @author Home
 */
public class RTSServlet extends HttpServlet{
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String rts = request.getParameter("rts");
        response.setContentType("application/pdf");
        ServletOutputStream out = response.getOutputStream();
        Connection conn = null;

        Document document = new Document(PageSize.A4,-30,-65,1,1);
        try{
            
            PdfWriter.getInstance(document, out);
            //left rigth top buttom
            document.setMargins(-30,-65,1,1) ;
          //  document.setMargins(0.5f,1.0f,1.0f,2.5f) ;
            document.setMarginMirroring(true);
            //document.setMargins(0.5f,2.5f,1.5f,1.0f) ;
            document.open();
            Usuario us = (Usuario)request.getSession().getAttribute("usuario");
           /* System.out.println("Usus "+us.getNgradDescripcion());
            System.out.println("Usus "+us.getDependencia());
            System.out.println("Usus "+us.getDependencia().getCdepeSiglas());
            System.out.println("Usus "+us.getDependencia().getNdepeIdentificador());
            System.out.println("Usus "+us.getDependencia().getCdepeNombre());*/
            document.add(PDFrts.createFirstTable(rts, us ));
            document.close();

        }catch(DocumentException e){
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
